package com.vf.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vf.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vf.common.annotation.Log;
import com.vf.common.core.controller.BaseController;
import com.vf.common.core.domain.AjaxResult;
import com.vf.common.enums.BusinessType;
import com.vf.user.domain.UserTags;
import com.vf.user.service.IUserTagsService;
import com.vf.common.utils.poi.ExcelUtil;
import com.vf.common.core.page.TableDataInfo;

/**
 * 用户和标签绑定Controller
 * 
 * @author LBS
 * @date 2025-06-04
 */
@RestController
@Api(tags="用户与标签")
@RequestMapping("/user/userTags")
public class UserTagsController extends BaseController
{
    @Autowired
    private IUserTagsService userTagsService;

    /**
     * 查询用户和标签绑定列表
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserTags userTags)
    {
        startPage();
        List<UserTags> list = userTagsService.selectUserTagsList(userTags);
        return getDataTable(list);
    }

    /**
     * 导出用户和标签绑定列表
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:export')")
    @Log(title = "用户和标签绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserTags userTags)
    {
        List<UserTags> list = userTagsService.selectUserTagsList(userTags);
        ExcelUtil<UserTags> util = new ExcelUtil<UserTags>(UserTags.class);
        util.exportExcel(response, list, "用户和标签绑定数据");
    }

    /**
     * 获取用户和标签绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(userTagsService.selectUserTagsByUserId(userId));
    }

    /**
     * 新增用户和标签绑定
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:add')")
    @Log(title = "用户和标签绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserTags userTags)
    {
        return toAjax(userTagsService.insertUserTags(userTags));
    }

    /**
     * 修改用户和标签绑定
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:edit')")
    @Log(title = "用户和标签绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserTags userTags)
    {
        return toAjax(userTagsService.updateUserTags(userTags));
    }

    /**
     * 删除用户和标签绑定
     */
    @PreAuthorize("@ss.hasPermi('user:userTags:remove')")
    @Log(title = "用户和标签绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userTagsService.deleteUserTagsByUserIds(userIds));
    }

    @ApiOperation("通过用户ID获取用户和标签绑定")
    @PreAuthorize("@ss.hasPermi('user:userTags:remove')")
    @Anonymous
    @RequestMapping("/getTagesById")
    public AjaxResult getTagesById(Long userId){
        return AjaxResult.success(userTagsService.selectUserTagsByUserId(userId));
    }


}
